<!--select2样式 start -->
<link href="__LIB__/select2-4.0.3/dist/css/select2.min.css" rel="stylesheet" />

<div class="page-container">
    <?php use think\Db;?>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="driver_he_th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr class="text-c">
            {include file="driver_he_td" /}
            <td class="f-14">
                {if $vo.status != 1 && $vo.status != 0}
                <!-- <a title="编辑" href="javascript:;" onclick="layer_open('编辑','/admin/hotel/driver_he_add/type/edit/id/{$vo.id}')" class="label label-warning radius" >编辑</a> -->
                <button type="button" class="btn btn-warning radius edit_item">编辑</button>
                <button type="button" class="btn btn-warning radius more_item" onclick="layer_open('更多','/admin/hotel/driver_he_add/type/edit/id/{$vo.group_id}')">更多</button>
                <div class="finish_edit" style="display: none;">
                    <button type="button" class="btn btn-primary radius submit_edit" onclick="submitSriver('{$vo.id}')">提交</button>
                    <button type="button" class="btn btn-default radius cancel_edit">取消</button>
                </div>
                {/if}
                {if $vo.status == 0}
                <!-- <a title="再次申请" href="javascript:;" onclick="layer_open('再次申请','/admin/hotel/driver_he_add/type/edit/id/{$vo.id}')" class="label label-warning radius" >再次申请</a> -->
                <button type="button" class="btn btn-warning radius edit_item">再次申请</button>
                <div class="finish_edit" style="display: none;">
                    <button type="button" class="btn btn-primary radius submit_edit" onclick="submitSriver('{$vo.id}')">提交</button>
                    <button type="button" class="btn btn-default radius cancel_edit">取消</button>
                </div>
                {/if}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
{if $is_ajax == 1}
{block name="script"}
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<!--select2 js 插件-->
<script type="text/javascript" src="__LIB__/select2-4.0.3/dist/js/select2.min.js"></script>
<script>
    //无刷新分页
    $(document).on('click','.pagination a',function (event) {
        var url = $(this).attr('href');
        $.ajax({
            type: 'get',
            url: url,
            success: function (data) {
                $('#test').html(data)
            }
        });
        return false;
    });

    function submitSriver(id) {
        console.log('id',id)
        $.ajax({
            type: 'post',
            url: '/admin/hotel/driver_he_add',
            data: {
                id:id,
                type:'edit',
                check_in_date:$("#check_in_date"+id).val(),
                hotel_name:$("#hotel_name"+id).val(),
                room_type_name:$("#room_type_name"+id).val(),
                days:$("#days"+id).val(),
                unit_price:$("#unit_price"+id).val(),
            },
            success: function (data) {
                if (data.code == 0) {
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                        $(this).parents('.text-c').find('.normal_status').show();
                        $(this).parents('.text-c').find('.edit_status').hide();
                        $(this).parents('.text-c').find('.edit_item').show();
                        $(this).parents('.text-c').find('.finish_edit').hide();
                        location.reload()
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5,
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function () {
//                        $(this).parents('.text-c').find('.normal_status').show();
//                        $(this).parents('.text-c').find('.edit_status').hide();
//                        $(this).parents('.text-c').find('.edit_item').show();
//                        $(this).parents('.text-c').find('.finish_edit').hide();
                    });
                }
            },
            error: function (data) {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                });
                console.log('data', data);
            }
        })
    }

    //全选
    $('#checkAlls').bind("click", function () {
        $("#ck").css('display','inline')
        var ck_temp =  $("input:checked[name='id[]']");
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked;
        if (sonChecked && allChecked){
            var ck_arr = $("#ck").children();
            var ck_len = ck_arr.length
            var dataArr = new Array
            if(ck_len > 0){
                for(var i = 0;i < ck_len;i++){
                    dataArr.push(ck_arr[i].innerText)
                }
            }

            $('#xuan').css('display','inline'); // 显示选择excel导出数据
            $('#sou').css('display','none') ;// 隐藏部分或全部excel导出数据

            var radioData =  $("input:checked[name='id[]']");
            console.log('radioData',radioData)
            var ck = radioData.serializeArray();
            var len = ck.length;
            for(var i=0;i<len;i++){
                if(dataArr.length > 0){
                    for(var z = 0;z < dataArr.length; z++){
                        if(dataArr[z] != ck[i]['value']){
                            $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" style="padding: 2px 6px;margin: 2px" id='+ck[i]['value']+'>'+ck[i]['value']+'</span>')
                        }
                    }
                }else{
                    $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" style="padding: 2px 6px;margin: 2px" id='+ck[i]['value']+'>'+ck[i]['value']+'</span>')
                }
            }
            ck.push({name: 'search',value: 'all'})
        }else{
            var len_ck = ck_temp.length;
            for(var y = 0;y < len_ck; y++){
                var temp_id = "#"+ck_temp[y]['value'];
                $(temp_id).remove()
            }
            $('#xuan').css('display','none');
            $('#sou').css('display','inline')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    //单选
    function single(e) {
        $("#ck").css('display','inline')
        var ck = $(e).is(':checked')
        if(ck){
            var checked_len = $("input:checkbox:checked").length;
            var list_len = $("input[name='id[]']").length;
            if(list_len == checked_len){
                $('#checkAlls').prop('checked',true);
            }
            console.log('checked_len',checked_len)
            console.log('list_len',list_len)
            var val = $(e).val()
            $(e).prop('checked',true)
            $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" id='+val+' style="padding: 2px 6px;margin: 2px">'+val+'</span>');
        }else{
            var temp_id = "#"+$(e).val()
            $(temp_id).remove();
            $(e).attr('checked',false)
        }
    }

    function cancel(e) {
        var temp_id = "#"+$(e).attr('id')
        var temp_id_2 = "#ck_"+$(e).attr('id')
        $(temp_id_2).prop("checked",false);
        $(temp_id).remove();
    }

    function xuan() {
        var ck_arr = $("#ck").children();
        var ck_len = ck_arr.length
        var dataArr = new Array
        if(ck_len<=0){
            layer.msg('请进行勾选！', {
                time: 2000,
            });
            return true;
        }else{
            for(var i = 0;i < ck_len;i++){
                // dataArr.push({value:ck_arr[i].innerText})
                dataArr.push(ck_arr[i].innerText)
            }
            $.ajax({
                type: 'post',
                url: '/admin/hotel/get_excel',
                data: {ids:dataArr},
                success: function (res) {
                    if (res.code == 5){
                        // console.log('data', res);
                        location.href = res.msg; // 下载文件
                        // 删除文件
                        unclinkFile(res.msg)
                        layer.msg('导出数据成功');
                    } else {
                        layer_open('excel导出数据','/admin/pub/role/id/1')
                    }
                }
            });
        }
    }
    var  value = 1;
    setTimeout(unclinkFile,1200000,value); // 延迟20分钟1200000
    // 15分钟后删除文件-900000
    function unclinkFile(val) {
        console.log(val)
        setTimeout(function () {
            // 删除文件
            $.ajax({
                type: 'post',
                url: '/admin/order/del',
                data: {val:val},
                success: function (data) {
                    console.log('data', data)
                    if (data.code != 5) {
                        console.log('删除失败', data.msg)
                    }
                }
            })
        },120000,val); // 2分钟后执行
    }

</script>
<script>

    var room_type_id = $("#room_type_id").select2({
        language: "zh-CN", //设置 提示语言
        width: "100%", //设置下拉框的宽度
        theme: "classic"
    })
    {notempty name = "Request.param.room_type_id"}
    room_type_id.val("{$Request.param.room_type_id}").trigger("change");
    {/notempty}
</script>
{/block}
{/if}

<script>
    function driverInfo(id) {
        var url = '/admin/driver/details';
        if (!id){
            layer.msg('缺少必要的参数');
        }
        $.ajax({
            type: 'get',
            url: url,
            data:{ id: id },
            success: function (data) {
                if (data.code == 1){
                    layer.msg(data.msg)
                    return false
                }else{
                    layer_open('详细资料','/admin/driver/details/id/'+id,{w:'1300px',h:'750px'})
                }
            }
        })
    }
</script>